import type {Executor} from '../';

export class HttpAiController {

    constructor(private executor: Executor) {
    }

    ask: (options: HttpAiControllerOptions['ask']) => Promise<
        string
    > = async (options) => {
        let _uri = '/aiutil/ask';
        let _separator = _uri.indexOf('?') === -1 ? '?' : '&';
        let _value: any = undefined;
        _value = options.question;
        _uri += _separator
        _uri += 'question='
        _uri += encodeURIComponent(_value);
        _separator = '&';
        _value = options.promptTemplate;
        _uri += _separator
        _uri += 'promptTemplate='
        _uri += encodeURIComponent(_value);
        _separator = '&';
        _value = options.chatModel;
        _uri += _separator
        _uri += 'chatModel='
        _uri += encodeURIComponent(_value);
        _separator = '&';
        _value = options.formatJson;
        _uri += _separator
        _uri += 'formatJson='
        _uri += encodeURIComponent(_value);
        _separator = '&';
        return (await this.executor({uri: _uri, method: 'GET'})) as Promise<string>;
    }
}

export type HttpAiControllerOptions = {
    'ask': {
        question: string,
        promptTemplate: string,
        chatModel: string,
        formatJson: string
    }
}